package org.smart4j.framework.dwtest.并发.semaphore;

import java.util.concurrent.Semaphore;

/**
 * Created by
 *
 * @author dw
 * @date 2018/02/01
 */
public class Driver {
    private Semaphore semaphore = null;

    public Driver() {
        this.semaphore = new Semaphore(1);
    }

    public Driver(int semaphore) {
        this.semaphore = new Semaphore(semaphore);
    }

    public void driverCar() {
        try {
            semaphore.acquire();
            //业务操作
            int i = 9 / 6;
            //System.out.println(Thread.currentThread().getName() + "进行业务处理" + "此时线程并发数:" + this.semaphore);
            semaphore.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
